<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<html>
	<head>
		<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
		<title>发票申请-金融风险管理系统</title>
		<script src="${contextPath}/scripts/jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
		<script src="${contextPath}/scripts/common.js" type="text/javascript"></script>
		<script src="${contextPath}/scripts/scriptvalidator.js" type="text/javascript"></script>
		<link href="${contextPath}/styles/default.css" rel="stylesheet" type="text/css" />
		<script language='javascript'>
		function jumpPage(page) {
			var id = document.getElementById("enId").value;
			var form1 = document.form1;
			form1.action = "<s:property value='contextPath'/>/mf/apply/edit.do?currentPage=" + page;
			form1.submit();
		}
		
		function billEdit(id) {
			buildIds();
			var form1 = document.form1;
			form1.action = "<s:property value='contextPath'/>/mf/apply/billEdit.do?currentPage=${currentPage}&entity.id="+id;
			form1.submit();
		}
		function billDel(id) {
			if(confirm("确认删除该店铺吗?")){
				buildIds();
				var form1 = document.form1;
				form1.action = "<s:property value='contextPath'/>/mf/apply/billDel.do?currentPage=${currentPage}&entity.id="+id;
				form1.submit();
			}
		}
		  
		function exportmf(){
			var form1 = document.form1;
			form1.action = "<s:property value='contextPath'/>/mf/apply/exportBillShopx.do";
			form1.submit();
		}
		
	  $(document).ready(function(){
			$("[type=button][name='btn_submit']").click(function(e){
				if('checkin'==e.target.id){
					if($("#tab_data tr").length<=2){
						alert("此申请没有包含任何管理费,暂时不能提交");
						return;
					}
					$("#operate").val(1);
				}
				buildIds();
				var form1 = document.form1;
				form1.action = "<s:property value='contextPath'/>/mf/apply/update.do";
				form1.submit();
			}); 
			
			});
	  
	  function buildIds(){
		  var check =$("input[name='ckfin']:checked"); //得到所有被选中的单独开票(金融机构)checkbox
		  var checkmons = $("input[name='ckmon']:checked"); //得到所有被选中的单独开票(月份)checkbox
		   var ids='',idmons='';              //定义变量
		   check.each(function(i){         //拼装单独开票(金融机构)选中项的值
			   if(i!=check.length-1){
				   ids+=$(this).val()+',';
			   }else{
				   ids+=$(this).val();
			   }
		    });
		   $("#ids").val(ids);
		   checkmons.each(function(j){         //拼装单独开票(月份)选中项的值
			   if(j!=checkmons.length-1){
				   idmons+=$(this).val()+',';
			   }else{
				   idmons+=$(this).val();
			   }
		    });
		   $("#idmons").val(idmons);
	  }
	  
	function selectShop(){
		window.open("selectAdvanceShop.do", "newwindow", "height=450, width=700, toolbar =no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	}
	
	function selectShopCallBack(hao, ming, id){
		 //document.getElementById("shop").value="("+hao+"/"+ming+")";
		 //document.getElementById("shopId").value=id;
		 this.doAjaxTest(hao,id);
	}
	
	function doAjaxTest(shopMark,shopId){
		var f=true;
		$("#tab_data tr").each(function() {
			var mark = $(this).children('td').eq(1).text();
			if(shopMark==mark){
				f=false;
				return;
			}
				
		});
		if(f){
			$("#shopId").val(shopId);
			buildIds();
			$("#form1").submit();
		}
	}
		</script>
	</head>
	<body  leftmargin='8' topmargin='8'>
	<div class="navigation">
	    <span><a href="${contextPath}/mf/apply/index.do"><img src="${contextPath}/images/back_nav_btn.png" /></a>
	    <a href="${contextPath}/mf/apply/index.do">返回</a>
	    <a href="javascript:window.history.forward();"><img src="${contextPath}/images/go_nav_btn.png" /></a>
	     <a href="javascript:window.history.forward();">前进</a>
	    <a href="javascript:window.location.reload();"><img src="${contextPath}/images/refresh_nav_btn.png" /></a>
	     <a href="javascript:window.location.reload();">刷新</a>
 	    </span>管理费&gt;&gt;发票申请
    
  	</div>
		<div class="xt_main_right_center">
		<form id="form1" name="form1" action="update.do" method="post" onSubmit="return Validator.Validate(this,3)">
			<table width="100%" border="0" cellpadding="1" cellspacing="1">
			<tr>
				<td class="left-td-width-bg">
					批次号：
				</td>
				<td width="30%" class="bline" align="left">
					<input name="entity.applyNum" value="<s:property value='entity.applyNum'/>" dataType="Require" msg="批次号不能为空" />
				</td>
				<td class="left-td-width-bg">
					申请人：
				</td>
				<td width="45%" class="bline" align="left">
					<s:property value="entity.applyUser.realName"/>
				</td>
			</tr>
		</table>
	
		<!-- 列表开始 -->	
		<s:if test="detailData!=null">
			<br/>
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
			  <tr>
			    <td height="25" align="left"><font color="#0066CC"><strong>管理费清单：</strong></font></td>
			    <td height="25" align="right"><input type="button" name="btn_add" id="btn_add" onclick="selectShop()" value="新增店铺"/></td>
			  </tr>
			</table> 
			<table id="tab_data" width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
			  <tr> 
			    <td width="4%" class="top-td-width-bg">序号</td>
			    <td width="8%" class="top-td-width-bg">店号</td>
			    <td width="12%" class="top-td-width-bg">店名</td>
			    <td width="12%" class="top-td-width-bg">驻店顾问</td>
			    <td width="12%" class="top-td-width-bg">区域经理</td>
			    <s:iterator value="financials">
			    	<td width="<s:property value='25/financials.size'/>%" class="top-td-width-bg"><s:property value="name"/></td>
			    </s:iterator>
			    <td width="8%" class="top-td-width-bg">总计</td>
			    <td width="7%" class="top-td-width-bg">单独开票(月份)</td>
			    <td width="7%" class="top-td-width-bg">单独开票(金融机构)</td>
			    <td width="8%" class="top-td-width-bg">操作</td>
			  </tr>
			 <s:iterator value="detailData" id="objs" status="stx" >
				<tr height="26" align="center" bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';" onmouseout="javascript:this.bgColor='#FFFFFF';">
					<td  class="down-center-td-width-bg">
						<s:property value="#stx.index+1"/>
					</td> 
				 	<s:iterator value="#objs" id="obj" status="st">
				 		<s:if test="#st.index==3">
				 			<td class="down-center-td-width-bg"><s:property value="getShopUserNames(#objs[0])"/></td>
				 			<td class="down-center-td-width-bg"><s:property value="getAreaManagerNames(#objs[0])"/></td>	
				 		</s:if>
				 		<s:if test="#st.Last">
				 			<td class="down-center-td-width-bg">
				 				<input type="checkbox" name="ckfin" value="<s:property value="#objs[0]"/>" <s:if test="#obj">checked="checked"</s:if> />
				 			</td>
				 		</s:if>
				 		<s:if test="#st.index==#objs.length-2">
				 			<td class="down-center-td-width-bg">
				 				<input type="checkbox" name="ckmon" value="<s:property value="#objs[0]"/>" <s:if test="#obj">checked="checked"</s:if> />
				 			</td>
				 		</s:if>
				 		<s:elseif test="#st.index!=0&&!#st.Last">
				 			<td class="down-center-td-width-bg"><s:property value="#obj"/></td>
				 		</s:elseif>
				 	</s:iterator>
				 	<td  class="down-center-td-width-bg">
						<a href="javascript:billEdit(<s:property value="#objs[0]"/>)" title="详情"><img src="${contextPath}/images/chakan.gif" alt="详情" width="16" height="18" border="0" /></a>
						<a href="javascript:billDel(<s:property value="#objs[0]"/>)" title="删除"><img src="${contextPath}/images/del.gif" alt="删除" width="16" height="13" border="0" /></a>
					</td> 
				</tr>
			</s:iterator>
			<tr bgcolor="#F9FCEF"> 
			 <td height="36" colspan="<s:property value='financials.size+9'/>" align="center">
					<%@ include file="/WEB-INF/view/common/pagination.jsp"%>
			 </td>
			</tr>
			</table>
			
			<table width="100%" border="0" cellpadding="1" cellspacing="1">
			<tr style="padding-top: 20px">
				<td class="bline" colspan="4" align="center">
				<%-- <img src="${contextPath}/images/export.png" alt="导出"  /> --%>
				<a href="javascript:exportmf()"><input type="button" onclick="exportmf()" value="导出"/></a>
					&nbsp;<input type="button" name="btn_submit" id="checkin" value="申请开票"/>
					&nbsp;<input type="button" name="btn_submit" id="save" value="暂存"/>
					&nbsp;<input type="button" onclick="javascript:window.history.back();" value="返回"/>
				</td>
			</tr>
			</table>
		
			<br/>
		</s:if>
		<input type="hidden" id="enId" name="id" value="<s:property value='entity.id'/>" />
		<input type="hidden" id="operate" name="operate" value="0" />
		<input type="hidden" id="shopId" name="shopId" />
		<input type="hidden" id="ids" name="ids" value="" />
		<input type="hidden" id="idmons" name="idmons" value="" />
		</form>
		</div>
	</body>
</html>